define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'meridconfig/index',
                    add_url: 'meridconfig/add',
                    edit_url: 'meridconfig/edit',
                    del_url: 'meridconfig/del',
                    multi_url: 'meridconfig/multi',
                    table: 'merid_config',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merid', title: __('Merid')},
                        {field: 'reg_need_recommend', title: __('Reg_need_recommend')},
                        {field: 'dev_key', title: __('Dev_key')},
                        {field: 'dev_user', title: __('Dev_user')},
                        {field: 'dev_flag', title: __('Dev_flag'), formatter: Table.api.formatter.flag},
                        {field: 'dev_login', title: __('Dev_login')},
                        {field: 'dev_url', title: __('Dev_url'), formatter: Table.api.formatter.url},
                        {field: 'dev_user_pwd', title: __('Dev_user_pwd')},
                        {field: 'iot_key', title: __('Iot_key')},
                        {field: 'iot_user', title: __('Iot_user')},
                        {field: 'iot_url', title: __('Iot_url'), formatter: Table.api.formatter.url},
                        {field: 'call_fee', title: __('Call_fee')},
                        {field: 'max_call_time', title: __('Max_call_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'reg_protocol', title: __('Reg_protocol')},
                        {field: 'qq_key', title: __('Qq_key')},
                        {field: 'qq_appid', title: __('Qq_appid')},
                        {field: 'wx_appsecret', title: __('Wx_appsecret')},
                        {field: 'wx_appid', title: __('Wx_appid')},
                        {field: 'test', title: __('Test')},
                        {field: 'recharge_send_sms', title: __('Recharge_send_sms')},
                        {field: 'recharge_template_id', title: __('Recharge_template_id')},
                        {field: 'integral_name', title: __('Integral_name')},
                        {field: 'balance_name', title: __('Balance_name')},
                        {field: 'phone_balance', title: __('Phone_balance')},
                        {field: 'voucher_balance', title: __('Voucher_balance')},
                        {field: 'share_user_level', title: __('Share_user_level')},
                        {field: 'appstore_version', title: __('Appstore_version')},
                        {field: 'user_level_0', title: __('User_level_0')},
                        {field: 'user_level_1', title: __('User_level_1')},
                        {field: 'user_level_2', title: __('User_level_2')},
                        {field: 'user_level_3', title: __('User_level_3')},
                        {field: 'user_level_4', title: __('User_level_4')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});